package src.mcpichess.pieces;

import java.util.ArrayList;

import src.mcpichess.control.Main;


public class Pawn extends Piece{
	
	public Pawn(Main m){
		byte[][][] s = {
				{{0,0,0},{0,0,0},{0,0,0}},
				{{0,0,0},{0,0,0},{0,0,0}},
				{{0,0,0},{0,1,0},{0,0,0}},		//Pawn
				{{0,0,0},{0,1,0},{0,0,0}},
				{{1,1,1},{1,1,1},{1,1,1}},
			};
		structure = s;
		main = m;
	}
	
	@Override
	public ArrayList<int[]> getMoves(int x, int z, int player) {
		ArrayList<int[]> rList = new ArrayList<int[]>();
		if (player == 1){
			if (z == 1){
				for (int a = 1; a <=2; a++){
					if (main.getPlayerAt(Main.pair(x, z+a)) == 0){
						rList.add(Main.pair(x, z+a));
					}else{
						a=3;
					}
				}
			}else{
				if (main.getPlayerAt(Main.pair(x, z+1)) == 0){
					rList.add(Main.pair(x, z+1));
				}
			}
			int diag1 = main.getPlayerAt(Main.pair(x+1, z+1));
			int diag2 = main.getPlayerAt(Main.pair(x-1, z+1));

			if (diag1 == 2){
				rList.add(Main.pair(x+1, z+1));
			}
			
			if (diag2 == 2){
				rList.add(Main.pair(x-1, z+1));
			}
		}
	
		if (player == 2){
			if (z == 6){
				for (int a = 1; a <=2; a++){
					if (main.getPlayerAt(Main.pair(x, z-a)) == 0){
						rList.add(Main.pair(x, z-a));
					}else{
						a=3;
					}
				}
			}else{
				if (main.getPlayerAt(Main.pair(x, z-1)) == 0){
					rList.add(Main.pair(x, z-1));
				}
			}
			int diag1 = main.getPlayerAt(Main.pair(x+1, z-1));
			int diag2 = main.getPlayerAt(Main.pair(x-1, z-1));

			if (diag1 == 1){
				rList.add(Main.pair(x+1, z-1));
			}
			
			if (diag2 == 1){
				rList.add(Main.pair(x-1, z-1));
			}
		}
		
		return rList;
		
	}

	@Override
	public int getBlockAt(int x, int y, int z) {
		return structure[y][z][x];
	}
	
	@Override
	public int getNum() {
		return 1;
	}
	
}
